package bigo.todolist.avocado;

import java.util.List;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

/**
 * Map activity for the task list activity map button
 * @author Alex Irlik
 *
 */
public class TaskMapActivity extends MapActivity {
	
	TaskMapView mapView;
	MapController mc;
	List<Overlay> listOfOverLays;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.taskmapview);
        
        
        mapView = (TaskMapView) findViewById(R.id.mapview2);
        mapView.setBuiltInZoomControls(true); //Set zoom control on
        mc = mapView.getController();
         
        String coordinates[] = {"33", "-84"};
        double lat = Double.parseDouble(coordinates[0]); //Set default coordinates
        double lng = Double.parseDouble(coordinates[1]);

        GeoPoint p = new GeoPoint(
        (int) (lat * 1E6),
        (int) (lng * 1E6));

        mc.animateTo(p);
        mc.setZoom(9); //Set zoom level
        
        loadMapOverlays(); //Load the tasks onto the map
        
        mapView.invalidate();
    }


	/**
	 * For routes
	 */
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
	
	/**
	 * Place tasks onto the map
	 */
	public void loadMapOverlays(){
		listOfOverLays = mapView.getOverlays();
		listOfOverLays.clear();
		Bundle sendTaskList = getIntent().getExtras(); //Get tasks, decriptions, and coordinates from the bundles
		String[] taskNameList = sendTaskList.getStringArray("taskNameList");
		String[] taskDescList = sendTaskList.getStringArray("taskDescriptionList");
		double[] tasklocList = sendTaskList.getDoubleArray("taskLocList");
		int k = 0; 
		
		
		for (int i = 0; i < taskNameList.length; i++ ){	//Loop through and place each item on the map
					int longitude = (int) tasklocList[k];
					int latitude = (int) tasklocList[k+1];
					Log.w("Taskmaster", "Long check " + longitude);
					Log.w("Taskmaster", "Lat check " + latitude);
					k = k + 2;
					latitude = (int) (latitude * 1E6);
					longitude = (int) (longitude * 1E6);
					GeoPoint p = new GeoPoint (latitude,longitude);
					String name = taskNameList[i];
					String desc = taskDescList[i];
					Drawable drawable = getResources().getDrawable(R.drawable.ex);
					BigItemizedOverlay itemizedoverlay = new BigItemizedOverlay(drawable, this);
					OverlayItem overlayitem = new OverlayItem(p, name, desc);
					itemizedoverlay.addOverlay(overlayitem);
					listOfOverLays.add(itemizedoverlay);
				}
		
		//Extra contruction
		/*String name = taskNameList[0];
		String desc = taskDescList[0];
		GeoPoint p = new GeoPoint(
		        (int) (30 * 1E6),
		        (int) (71 * 1E6));
		Drawable drawable = getResources().getDrawable(R.drawable.ex);
    	BigItemizedOverlay itemizedoverlay = new BigItemizedOverlay(drawable, this);
    	OverlayItem overlayitem = new OverlayItem(p, name, desc);
    	itemizedoverlay.addOverlay(overlayitem);
    	listOfOverLays.add(itemizedoverlay);*/
		
	}

}
